package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.amnotaion.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 因为这个需要数据回显ID，我们就用注解的方式实现
     */
    @Insert("insert into dish(name,category_id,price,image,description,status,create_time,update_time,create_user,update_user)VALUES" +
            "(#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void addDish(Dish dishEntity);

    Page<DishVO> pageSelectDish(DishPageQueryDTO dishPageQueryDTO);

    void deleteDish(List<Integer> ids);

    Dish selectByIdDish(Integer id);

    List<Dish> list(Integer categoryId);

    void updateStatusDish(Dish dish);

    @Select("select * from dish")
    List<Dish> selectAll();

}
